const Panel = require("../gmoon/basePanel");
cc.Class({
    extends: Panel,

    properties: {

    },

    initSprites(){
        
        if( this.getAttr("_inited")) return;
        let nodes = [
            "logo",
            "logobg",
            "logozsq",
            "logozsqST",
            "logozsqSD",
            "logotitle" ,
            //"levelLogo",
            "beginBtn"
        ]
        for(let i in nodes){
            let p = this.getChildOriInfo(nodes[i]);
            $T.setSprite( p.node , $RES.g("img-home-" + nodes[i]) );
        }

        this.setAttr("_inited" , true);
    },

    loadPanel(){
        this.initSprites();
        return new Promise(( res )=>{
            this.node.active = true;
            this._playBeginFilm()
            .then(()=>{
                res();
            });
        });
    },

    unLoadPanel(){
        return new Promise(( res )=>{
            this._playCloseFilm()
            .then(()=>{
                this.node.active = false;
                res();
            })
        });
    },

    _playCloseFilm(){
        const childNames = [
            {
                name : "logobg",
                offsetPos : cc.v2(-200 , 200),
                scale : 0,
                time : .2,
                delay : 0,
                easing : {easing: 'sineOut'}
            },
            {
                name : "logo",
                offsetPos : cc.v2(400 , 0),
                scale : 0,
                time : .1,
                delay : 0
            },
            {
                name : "logozsqSD",
                offsetPos : cc.v2(0 , 0),
                scale : 0,
                time : .05,
                delay : .3
            },
            {
                name : "logozsq",
                offsetPos : cc.v2(-500 , 0),
                //scale : .5,
                time : .1
            },
            {
                name : "logozsqST",
                offsetPos : cc.v2(0 , 0),
                scale : 0,
                time : .05
            },
            {
                name : "logotitle",
                offsetPos : cc.v2(0 ,800),
                scale : .6,
                time : .1,
                delay : .2
            },
            // {
            //     name : "levelLogo",
            //     offsetPos : cc.v2(-600 ,0),
            //     scale : .6,
            //     time : 1,
            //     delay : .3
            // },
            {
                name : "beginBtn",
                offsetPos : cc.v2(0 ,-900),
                scale : .6,
                time : 1,
                delay : .3
            }
        ];

        return this.playChildAnimate( childNames , true );
    },

    //执行动画
    _playBeginFilm(){
        const childNames = [
            {
                name : "logobg",
                offsetPos : cc.v2(-200 , 200),
                scale : .5,
                time : 1,
                delay : 0,
                easing : {easing: 'sineOut'}
            },
            {
                name : "logo",
                offsetPos : cc.v2(400 , 0),
                scale : .5,
                time : .2,
                delay : 0
            },
            {
                name : "logozsqSD",
                offsetPos : cc.v2(0 , 0),
                scale : .1,
                time : .05,
                delay : 1,
                fn : ( node )=>{
                    $Animate.do("playUnPop" , node );
                }
            },
            {
                name : "logozsq",
                offsetPos : cc.v2(-500 , 0),
                //scale : .5,
                time : .2,
                delay : .5
            },
            {
                name : "logozsqST",
                offsetPos : cc.v2(0 , 0),
                scale : .1,
                time : .05,
                delay : 1.3
            },
            {
                name : "logotitle",
                offsetPos : cc.v2(0 ,800),
                scale : .6,
                time : .1,
                delay : 1,
                fn : ( node )=>{
                    $Animate.do("playPop" , node );
                }
            },
            {
                name : "logotitle",
                offsetPos : cc.v2(0 ,0),
                delay : 1,
                fn : ( node )=>{
                    let levelbar = $T.find("levelshow" , $G.get("rootcanvas"));
                    $T.getScr(levelbar).homeShow();
                }
            },
            {
                name : "beginBtn",
                offsetPos : cc.v2(0 ,-900),
                scale : .6,
                time : .2,
                delay : 1,
                fn : ( node )=>{
                    $Animate.do("playPop" , node , 0 , {u:.2 , d:-0.1});
                }
            }
        ];

        return this.playChildAnimate( childNames );
    }
});
